package com.woniuxy.business.controller;

import com.woniuxy.business.service.impl.BusinessInfoServiceImpl;
import com.woniuxy.entity.BusinessInfo;
import com.woniuxy.utils.ResponseResult;
import com.woniuxy.utils.ResultStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/businessInfo")
public class BusinessInfoController {
    @Resource
    private BusinessInfoServiceImpl businessInfoService;

    //通过企业名称查找企业信息
    @GetMapping("/BusinessName/{businessName}")
    public ResponseResult<BusinessInfo> getBusinessInfoByBusinessName(@PathVariable("businessName") String business_name){
        ResponseResult<BusinessInfo> responseResult = new ResponseResult<>();
        responseResult.setStatus(ResultStatus.REQUEST_SUCCESS);
        responseResult.setCode(200);
        responseResult.setMessage("请求成功");
        responseResult.setData(businessInfoService.getBusinessInfoByBusinessName(business_name));
        return responseResult;
    }

    //查找所有企业
    @GetMapping("/getAll")
    public ResponseResult getAllBusinessInfo(String business_name,int pageIndex, int pageSize){
        ResponseResult<List<BusinessInfo>> responseResult = new ResponseResult<>();
        responseResult.setStatus(ResultStatus.REQUEST_SUCCESS);
        responseResult.setCode(200);
        responseResult.setMessage("查找成功");
        responseResult.setData(businessInfoService.getAllBusinessInfo(business_name,pageIndex,pageSize));
        return responseResult;
    }

    //根据id查找企业
    @GetMapping("/{id}")
    public ResponseResult<BusinessInfo> getBusinessInfoById(@PathVariable("id") int id){
        ResponseResult<BusinessInfo> responseResult = new ResponseResult<>();
        responseResult.setStatus(ResultStatus.REQUEST_SUCCESS);
        responseResult.setCode(200);
        responseResult.setMessage("查找成功");
        responseResult.setData(businessInfoService.selectBusinessInfoById(id));
        return responseResult;
    }

    //添加
    @PostMapping("/add")
    public ResponseResult addBusinessInfo(@RequestBody BusinessInfo businessInfo){
        ResponseResult<List<BusinessInfo>> responseResult = new ResponseResult<>();
        responseResult.setStatus(ResultStatus.REQUEST_SUCCESS);
        responseResult.setCode(200);
        responseResult.setMessage("添加成功");
        businessInfoService.addBusinessInfo(businessInfo);
        return  responseResult;
    }

    //删除
    @DeleteMapping("/delete/{business_name}")
    public ResponseResult removeBusinessInfo(@PathVariable("business_name") String business_name){
        ResponseResult<List<BusinessInfo>> responseResult = new ResponseResult<>();
        responseResult.setStatus(ResultStatus.REQUEST_SUCCESS);
        responseResult.setCode(200);
        responseResult.setMessage("删除成功");
        businessInfoService.removeBusinessInfo(business_name);
        return responseResult;
    }
}
